/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package telaCadastros;

import managertelaCadastros.managerCadFornecedor;
import telasMensagem.MensagemConfirmacao;
import util.Mensagem;

/**
 *
 * @author fumio
 */
public class CadFornecedor extends javax.swing.JDialog {
    private static CadFornecedor cadFornecedor;
    private static managerCadFornecedor managerCadFornecedor;
    /**
     * Creates new form CadGeneric
     */
    public CadFornecedor(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setTitle("Cadastro de Fornecedor");
    }

   public static CadFornecedor getInstance(managerCadFornecedor mCadFornecedor) {
        cadFornecedor = new CadFornecedor(null, true);
        managerCadFornecedor = mCadFornecedor;
        return cadFornecedor;
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        btnConfirmar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        edtCodigo = new javax.swing.JTextField();
        edtCnpj = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        edtInscEstadual = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        edtRazao = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        edtFantasia = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        edtEndereco = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        edtNumero = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        edtBairro = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        edtComplemento = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        edtCep = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        edtCidade = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        edtRepresentante = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        edtTelefone = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        edtCelular = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        edtEmail = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        edtUF = new javax.swing.JTextField();
        edtCodCidade = new javax.swing.JTextField();
        btnPesquisarCidade = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel2.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnConfirmar.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        btnConfirmar.setText("Confirmar");
        btnConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConfirmarActionPerformed(evt);
            }
        });
        jPanel2.add(btnConfirmar, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 10, 120, 75));

        btnCancelar.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        jPanel2.add(btnCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(144, 10, 120, 75));

        btnSair.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N
        btnSair.setText("Sair");
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel2.add(btnSair, new org.netbeans.lib.awtextra.AbsoluteConstraints(580, 10, 120, 75));

        jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(null, new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel1.setText("Código");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 15, -1, -1));

        edtCodigo.setEditable(false);
        edtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtCodigoActionPerformed(evt);
            }
        });
        jPanel1.add(edtCodigo, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 38, 58, 30));

        edtCnpj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtCnpjActionPerformed(evt);
            }
        });
        jPanel1.add(edtCnpj, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 100, 240, 30));

        jLabel2.setText("CNPJ");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 80, -1, -1));
        jPanel1.add(edtInscEstadual, new org.netbeans.lib.awtextra.AbsoluteConstraints(506, 100, 196, 30));

        jLabel3.setText("Insc. Estadual");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(506, 80, -1, -1));

        jLabel4.setText("Razão Social");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 143, -1, -1));
        jPanel1.add(edtRazao, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 166, 690, 30));

        jLabel5.setText("Fantasia");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 208, -1, -1));
        jPanel1.add(edtFantasia, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 228, 690, 30));

        jLabel6.setText("Endereço");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 270, -1, -1));
        jPanel1.add(edtEndereco, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 293, 578, 30));

        jLabel7.setText("Número:");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(607, 270, -1, -1));
        jPanel1.add(edtNumero, new org.netbeans.lib.awtextra.AbsoluteConstraints(607, 289, 100, 30));

        jLabel8.setText("Bairro");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 341, -1, -1));
        jPanel1.add(edtBairro, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 364, 345, 30));

        jLabel9.setText("Complemento");
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(374, 341, 140, -1));
        jPanel1.add(edtComplemento, new org.netbeans.lib.awtextra.AbsoluteConstraints(372, 364, 195, 30));

        jLabel10.setText("Cep");
        jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(577, 341, 46, 11));
        jPanel1.add(edtCep, new org.netbeans.lib.awtextra.AbsoluteConstraints(579, 364, 130, 30));

        jLabel11.setText("Cidade");
        jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 406, -1, -1));
        jPanel1.add(edtCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(157, 429, 408, 30));

        jLabel12.setText("Representante");
        jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 477, -1, -1));
        jPanel1.add(edtRepresentante, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 500, 407, 30));

        jLabel13.setText("Telefone");
        jPanel1.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(471, 477, -1, -1));
        jPanel1.add(edtTelefone, new org.netbeans.lib.awtextra.AbsoluteConstraints(436, 500, 129, 30));

        jLabel14.setText("Celular");
        jPanel1.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(632, 477, -1, -1));
        jPanel1.add(edtCelular, new org.netbeans.lib.awtextra.AbsoluteConstraints(577, 500, 130, 30));

        jLabel15.setText("Email");
        jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(15, 540, -1, -1));
        jPanel1.add(edtEmail, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 563, 690, 30));

        jLabel16.setText("UF");
        jPanel1.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(591, 406, -1, -1));
        jPanel1.add(edtUF, new org.netbeans.lib.awtextra.AbsoluteConstraints(577, 429, 130, 30));
        jPanel1.add(edtCodCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(17, 429, 64, 30));

        btnPesquisarCidade.setText("P");
        jPanel1.add(btnPesquisarCidade, new org.netbeans.lib.awtextra.AbsoluteConstraints(87, 429, 62, 30));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 729, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 725, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 5, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-744)/2, (screenSize.height-756)/2, 744, 756);
    }// </editor-fold>//GEN-END:initComponents

    private void btnConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConfirmarActionPerformed
        // TODO add your handling code here:

        MensagemConfirmacao msg = new MensagemConfirmacao(null, rootPaneCheckingEnabled);
        if (Mensagem.confirmarCadastro("Fornecedor")) {
           if (managerCadFornecedor.salvar()){
               
           }
           LimpaTela();
        }
    }//GEN-LAST:event_btnConfirmarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        LimpaTela();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed

    private void edtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtCodigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtCodigoActionPerformed

    private void edtCnpjActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtCnpjActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtCnpjActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConfirmar;
    public javax.swing.JButton btnPesquisarCidade;
    private javax.swing.JButton btnSair;
    public javax.swing.JTextField edtBairro;
    public javax.swing.JTextField edtCelular;
    public javax.swing.JTextField edtCep;
    public javax.swing.JTextField edtCidade;
    public javax.swing.JTextField edtCnpj;
    public javax.swing.JTextField edtCodCidade;
    public javax.swing.JTextField edtCodigo;
    public javax.swing.JTextField edtComplemento;
    public javax.swing.JTextField edtEmail;
    public javax.swing.JTextField edtEndereco;
    public javax.swing.JTextField edtFantasia;
    public javax.swing.JTextField edtInscEstadual;
    public javax.swing.JTextField edtNumero;
    public javax.swing.JTextField edtRazao;
    public javax.swing.JTextField edtRepresentante;
    public javax.swing.JTextField edtTelefone;
    public javax.swing.JTextField edtUF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

    private void LimpaTela() {
       edtCodigo.setText("");
       edtCnpj.setText("");
       edtInscEstadual.setText("");
       edtRazao.setText("");
       edtFantasia.setText("");
       edtEndereco.setText("");
       edtNumero.setText("");
       edtBairro.setText("");
       edtComplemento.setText("");
       edtCep.setText("");
       edtCodCidade.setText("");
       edtCidade.setText("");
       edtUF.setText("");
       edtRepresentante.setText("");
       edtTelefone.setText("");
       edtCelular.setText("");
       edtEmail.setText("");       
       }
}
